import {
	login
} from "@/api/login.js";

const user = {
	state: {
		accountName: "",
		avatar: "",
		realName: "",
		role: "",
	},
	mutations: {},
	actions: {
		// 用户登录
		Login({
			commit
		}, userInfo) {
			return new Promise((resolve, reject) => {
				const {
					username,
					password
				} = userInfo;
				login(username, password)
					.then((res) => {
						let {
							data
						} = res;
						console.log("用户信息---", res);
						uni.setStorageSync("uni-template-token", data.accessToken);
						resolve(res);
					})
					.catch((err) => {
						reject(err);
					});
			});
		},
		// 退出
		LogOut({
			commit
		}, state) {
			uni.removeStorageSync("uni-template-tokenn");
			uni.reLaunch({
				url: "/pages/login/index",
			});
		},
	},
};
export default user;